const gaud = new Gaud();
const textUtil = new Text_util();


//获取当前天气
setTimeout(function () {
    // 获取当前位置
    gaud.getCurrentLocation().then(address => {
        // 获取城市编码
        gaud.getCityCode(address).then(response => {
            // 获取当前天气
            gaud.getWeather(response.getElementsByTagName("adcode")[0].textContent).then(city => {
                let cloudy = document.getElementsByClassName("cloudy");
                let temperature = document.getElementsByClassName("temperature");
                let wind = document.getElementsByClassName("wind");
                let humidity = document.getElementsByClassName("humidity");
                let winPower = document.getElementsByClassName("win-power");
                let region = document.getElementsByClassName("region")

                console.log(city.lives[0].weather)
                cloudy[0].innerHTML = city.lives[0].weather;
                temperature[0].innerHTML = city.lives[0].temperature;
                wind[0].innerHTML = city.lives[0].winddirection;
                humidity[0].innerHTML = city.lives[0].humidity;
                winPower[0].innerHTML = city.lives[0].windpower;
                region[0].innerHTML = city.lives[0].province + "-" + city.lives[0].city;

                let locationText = document.getElementsByClassName("location-text")
                if (city.lives[0].weather === "阴") {
                    locationText[0].innerHTML = "心情是否好点?"
                } else if (city.lives[0].weather === "雨") {
                    locationText[0].innerHTML = "带伞了吗?"
                } else if (city.lives[0].weather === "雾") {
                    locationText[0].innerHTML = "开车注意"
                } else if (city.lives[0].weather === "晴") {
                    locationText[0].innerHTML = "今天好像很适合写工作"
                } else if (city.lives[0].weather === "多云") {
                    locationText[0].innerHTML = "暂时的多云泡杯coff如何?"
                } else {
                    locationText[0].innerHTML = "今日的天气很不错!"
                }

                //局部刷新
                let loading = document.getElementsByClassName("loading");
                let subassembly = document.getElementsByClassName("subassembly")
                loading[0].style.display = "none";
                subassembly[0].style.display = "block";


                let date = document.getElementById('current-time');

                // 实时时间
                // 先更新一次时间
                textUtil.updateTime(date);

                // 然后使用 setInterval 每秒更新一次时间
                setInterval(function () {
                    textUtil.updateTime(date);
                }, 1000);

            }).catch(error => {
                // 报错跳转页面
                console.log(error)
                window.location.href = "/www.xiaomi.com/error"
            })
        }).catch(error => {
            // 报错跳转页面
            console.log(error)
            window.location.href = "/www.xiaomi.com/error"
        });
    }).catch(error => {
        // 报错跳转页面
        console.log(error)
        window.location.href = "/www.xiaomi.com/error"
    });
}, 2000);

$(function () {
    $('.number-completed-ord').animateNumber(
        {
            number: $(".number-completed-ord").attr("number-completed-ord"), // 目标数值
            easing: 'swing', // 缓动函数
            duration: 500000 // 动画持续时间（毫秒）
        }
    );
    $('.after-sales-number').animateNumber(
        {
            number: $(".after-sales-number").attr("after-sales-number"), // 目标数值
            easing: 'swing', // 缓动函数
            duration: 500000 // 动画持续时间（毫秒）
        }
    );
    $('.number-not-shipped').animateNumber(
        {
            number: $(".number-not-shipped").attr("number-not-shipped"), // 目标数值
            easing: 'swing', // 缓动函数
            duration: 500000 // 动画持续时间（毫秒）
        }
    );
    $('.total-inventory-goods').animateNumber(
        {
            number: $(".total-inventory-goods").attr("total-inventory-goods"), // 目标数值
            easing: 'swing', // 缓动函数
            duration: 500000 // 动画持续时间（毫秒）
        }
    );
    let matter = new Matter();
    $('.dispose-matters').on("click",function () {
        matter.deleteMatterById($(this).attr("matters-id")).then(res=>{
            console.log(res)
            window.location.href = "/www.xiaomi.com/background/home?menuId=101"
        })
    })
})